
/**
 * 日期格式化
 */
function formatTimeString(time){
    if (time==null)
        return ""
    let y = time.getFullYear()
    let m = time.getMonth()+1
    let d = time.getDate()
    let h = time.getHours()
    let mi = time.getMinutes()
    let s = time.getSeconds()
    return `${y}-${m}-${d} ${h}:${mi}:${s}`;
}

/**
 * 时间对象转字符串
 * 如果是当天，则转时间字符串
 * 如果不是当天，则转日期字符串
 * @returns
 */
function formatDateOrTimeStr(time){
    if (time==null)
        return ""

    // let y = time.getFullYear()
    let m = time.getMonth()+1
    let d = time.getDate()
    let h = time.getHours()
    let mi = time.getMinutes()
    // let s = time.getSeconds()

    let now = new Date();
    if(now.getMonth()+1===m && now.getDate()===d) {
        return `${h<10?'0'+h:h}:${mi<10?'0'+mi:mi}`;
    } else {
        return `${m<10?'0'+m:m}-${d<10?'0'+d:d}`;
    }
}



export  {
    formatTimeString,
    formatDateOrTimeStr,
}